/**
 * YESBRAIN Javascript Library;
 * @author gongji
 */

/*
 * JSQL Server To Query/Operate SQL server like MySQL , MsSQL , Oracle , etc .
 * Can use full-function sql provided by server language
 * sql differences from server to server 
 * eg: MySql's SQL is different from MsSql;
 * but most of the basics are the same; 
 * 
 */

YESBRAIN.namespace("JSQL.Server");

YESBRAIN.JSQL.Server = {
		
		SQLProxyUrl : '',
		
		ServerHost : '',
		
		UserName : '',
		
		PassWord : '',
		
		DataBase : '',
		
		
		executeSQL : function(sql) {
			
			var sqlproxyurl = this.SQLProxyUrl ? this.SQLProxyUrl : _SQLPROXYURL_;
			var serverhost = this.ServerHost ? this.ServerHost : _SQLSERVERHOST_;
			var username = this.UserName ? this.UserName : _SQLUSERNAME_;
			var password = this.PassWord ? this.PassWord : _SQLPASSWORD_;
			var database = this.DataBase ? this.DataBase : _SQLDATABASE_;
			
			var callbackdata = [];
			var _successCallBack = function(data) {
				callbackdata = data;
			};
			var postdata = {
								host : serverhost,
								user : username,
								password : password,
								database : database,
								SQL : sql.toString()
							};
			$.ajaxSetup({async : false});
			$.ajax({
					type: 'POST',
		  			url: sqlproxyurl,
		  			data: postdata,
		  			success: _successCallBack
		  			//dataType: dataType
				});
			return eval(callbackdata);
		},
		
		querySQL : function(sql){
			return this.executeSQL(sql);
		}
}